    <%@ page language="java" contentType="text/html; charset=UTF-8"
             pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>二维码验证码</title>
    <style type="text/css">
        body{margin: 0;padding: 0; background: url(images/wx.jpg) no-repeat;background-size: 100%;font-family: "Microsoft yahei", sans-serif}
        .content{margin: 0;padding: 0;width: 100%;}
        .content-1{margin: 80px auto;padding: 0;width:380px;height: 400px; text-align: center;background-color: #fff;border-radius: 4px;}
        .content-1 img{width: 276px;  height: 276px;margin: 42px auto 5px;}
        .content-2{margin-top: 20px;font-size: 20px;}
    </style>
    <!-- <script src="jquery-2.1.4.min.js"></script> -->
    <script src="js/jquery-1.8.3.min.js"></script>
    <script src="js/layer/layer.js"></script>
</head>
<body>
<div class="content">
    <div class="content-1">
        <img src="/nsy-web/api/card/center?service_code=9001" id="wx">
        <div class="content-2"><span>扫描二维码登录</span></div>
    </div>
</div>
</body>
</html>
<script type="text/javascript">

	//全局变量
	var startTime = new Date().getTime();

   //$(function(){
    $(window).load(function(){
        $.ajax({
            type:"GET",
            url:"/nsy-web/api/card/center?service_code=9004",
            success:function(uid){
            	poll(uid);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert("error")
            }
        })
    });
    
    function poll(uid){

    	var service_code="9002";
        $.ajax({
            type:"GET",
            url:"/nsy-web/api/card/center",
            dataType:"script",
            data:{
                service_code:service_code,
                uid:uid
            },
            cache:false,
            success:function(b){
            
                switch (b){
                    case '200':
                    	var index =layer.load(2,{content:"loading..."});
                         window.location.href="/nsy-web/card/index.html" 
                       // location.replace("/nsy-web/index.jsp")
                        break;
                    case '408':
                    case '500':
                    	//alert(b);判断是否大于3分钟，如果大于，我就不调自己，刷新页面，如果小于，继续调自己
                    	var endTime = new Date().getTime();
                    	if((endTime-startTime)>180000){
                    		window.location.href='QR-code.jsp'
                    	}
                    	else{
                    		setTimeout(poll(uid), 500);
                    	}
                        break;
                    case '300':
                    	alert("没得到身份验证");
                    	//window.location.href='QR-code.jsp'
                    	break;
                }
            },
            error: function(a,b,c) {
                //alert("系统出错" + a + "=" + b + "=" + c);
                //window.location.href="QR-code.jsp"
            }
        });
        
    }
</script>
